<template>
	<!--新增界面-->
	<el-dialog v-loading.fullscreen.lock="loading" element-loading-text="处理中......" title="新增" :visible.sync="dialogVisible" size="small" :close-on-click-modal="false" :close-on-press-escape="false" :before-close="off" :top="dialog_margin_top">
		  <el-form label-width="150px" >
		  <el-row :span="24">
		  	<el-col :span="24">
        <el-form-item label="分/支公司代码">
          <el-select v-model="formData.comcode" placeholder="分/支公司代码" filterable @change="change()" size="small">
            <el-option v-for="item in comcodeOptions" :key="item.branchNo" :label="item.branchNo + '-'+ item.branchCname" :value="item.branchNo"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="险种代码">
          <el-select v-model="formData.riskcode" placeholder="险种代码" filterable size="small">
            <el-option v-for="item in riskcodeOptions" :key="item.riskcode" :label="item.riskcode + '-'+ item.riskcname" :value="item.riskcode"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="代理人代码">
          <el-select v-model="formData.agentcode" placeholder="代理人代码" filterable @click.native="valid()" size="small">
            <el-option v-for="item in agentcodeOptions" :key="item.userCode" :label="item.userCode + '-'+ item.userName" :value="item.userCode"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="是否见费出单">
          <el-select v-model="formData.ispolicypay" placeholder="是否见费出单" size="small">
            <el-option v-for="item in policypayOptions" :key="item.value" :label="item.value + '-'+ item.label" :value="item.value"></el-option>
          </el-select>
        </el-form-item>
		  	</el-col>
		  </el-row>
		</el-form>
		  <span slot="footer" class="dialog-footer">
			   <el-button @click="off">取 消</el-button>
			   <el-button type="warning" @click="add">保存</el-button>
		  </span>
	</el-dialog>
</template>

<script>
import PolicyPayAPI from "../../../../js/production/policypay/policyPayAPI"
export default {
  data() {
    return {
      dialog_margin_top: '5%',
      dialogVisible: true,
      formData: {
        comcode: '',
        riskcode: '',
        agentcode: '',
        ispolicypay: 'Y',
      },
      comcodeOptions: [],
      riskcodeOptions: [],
      agentcodeOptions: [],
      policypayOptions: [
        {label: '是', value: 'Y'},
        {label: '否', value: 'N'}
      ],
      loading: false,
      warning: false,
    }
  },
  mounted() {
    PolicyPayAPI.initCompanySelect(this);
    PolicyPayAPI.initRiskSelect(this);
  },
  methods: {
    add() {
      if (this.formData.comcode === '' || this.formData.riskcode === '' || this.formData.agentcode === '') {
        this.$message({type: 'error',message: '请将信息填写完整！'});
        return;
      }
      let vm = this;
      if (this.formData.agentcode === 'ALL') {
        this.$confirm('此操作将删除当前公司险种下的所有个性配置, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
            PolicyPayAPI.add(this);
        }).catch (() => {});
      } else {
        PolicyPayAPI.add(this);
      }
    },
    off() {
      this.$parent.showAddDialog = false;
    },
    change() {
      this.formData.agentcode = '';
      this.agentcodeOptions = [];
      PolicyPayAPI.initAgentSelect(this);
    },
    valid() {
      if (this.formData.comcode === '') {
        this.$message({type: 'error',message: '请先选择分/支公司代码！'});
        return;
      }
    }
  }
}
</script>
